using System;
using System.Collections.Generic;
using System.Text;
using Emlyn.Common.Tools.Encryption;
using Emlyn.Common.Tools.BusinessLayer;

namespace Emlyn.Website.Users
{
    public class User: BaseItem
    {
        public User()
            : base(true)
        {
            _userID = Guid.NewGuid();
            Initialise();
        }

        public User(Guid aUserID)
            : base(false)
        {
            _userID = aUserID;
            Initialise();
        }

        private void Initialise()
        {
            _authLevel = GlobalAuthLevel.Disabled;
            _email = null;
            CreateValidationCode();
        }

        private Guid _userID;

        public Guid UserID
        {
            get { return _userID; }
            set { _userID = value; }
        }

        private string _userName;

        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        private string _hashedPassword;

        public string HashedPassword
        {
            get { return _hashedPassword; }
            set { _hashedPassword = value; }
        }

        private GlobalAuthLevel _authLevel;

        public GlobalAuthLevel AuthLevel
        {
            get { return _authLevel; }
            set { _authLevel = value; }
        }

        private string _email;

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        private string _validationCode;

        public string ValidationCode
        {
            get { return _validationCode; }
            set { _validationCode = value; }
        }

        public void CreateValidationCode()
        {
            _validationCode = ((new Random()).Next(99999999)).ToString();
        }

        public bool Validated
        {
            get { return String.IsNullOrEmpty(_validationCode) || String.IsNullOrEmpty(_validationCode.Trim()); }
        }

        public void SetPassword(string aPassword)
        {
            OneWayHash loneWayHash = new OneWayHash();

            _hashedPassword = loneWayHash.Hash(aPassword);
        }

        string _websiteCode;

        public string WebsiteCode
        {
            get
            {
                return _websiteCode;
            }
            set
            {
                _websiteCode = value;
            }
        }
    }
}
